package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.FileService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件 前端控制器
 */
@RestController
@RequestMapping("/file")
public class FileController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private FileService fileServiceImpl;


    /**
     * 上传文件
     * @param request
     * @param file 文件
     * @param type 文件类型 1图片，2文本，3人脸
     * @return
     */
    @PostMapping("/upload")
    public Result upload(RequestParameterWrapper request, @RequestPart("file") MultipartFile file, @RequestParam("type")int type){

        logger.info("上传文件/图片/人脸");

        String schoolId = request.getParam("schoolId");

        return fileServiceImpl.upload(schoolId,file,type);
    }

    /**
     * 批量上传文件
     * @param request
     * @param file 文件
     * @param type 文件类型 1图片，2文本，3人脸,4视屏
     * @return
     *//*
    @PostMapping(value = "/batchUpload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public Result batchUpload(RequestParameterWrapper request, @RequestPart(value = "file") MultipartFile[] file, @RequestParam("type")int type) {

        logger.info("批量上传文件/图片/人脸");
        String schoolId = request.getParam("schoolId");

        return fileServiceImpl.batchUpload(schoolId,file,type);
    }*/
}
